home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / mikecom / support.asm < prev    next >
Assembly Source File  |  1987-05-16  |  7KB  |  185 lines

  1.  
  2. title SUPPORT FUNCTIONS FOR ASYNC ROUTINES
  3. page 75,132
  4.  
  5. ;-- Mike Dumdei, 6 Holly Lane, Texarkana TX 75503
  6.  
  7. include casmhdr.h
  8. defseg          COMM_TEXT
  9. include async.h
  10. IMPORT_WORD     <__port_dta_tbl>
  11.  
  12. _DATA           segment
  13. times_ten       dw      10
  14. _DATA           ends
  15.  
  16. begseg          COMM_TEXT
  17.  
  18. ;-----------------------------------------------------------------------------
  19. ; Procedure to check validity of port argument passed by calling function and
  20. ; load pointers specific to the selected port.
  21. ;
  22. ;   Entry: stack frame is setup
  23. ;
  24. ;   Exit : CY flag = port passed by C function out of range, AX == R_NOPORT
  25. ;          If NC, then SI = pntr to port_data && BX = port * 2 (rdy for indxg)
  26. ;          ZR flag = port has not been initialized
  27. ;          If NZ, then DX = base address for port I/O, port value was good,
  28. ;           SI = pointer to port data, & BX is ready to indx tables
  29. ;-----------------------------------------------------------------------------
  30. localproc       __ck_port_arg
  31. public          __ck_port_arg
  32.         mov     ax,Port         ;get function argument for comport nmbr
  33.         cmp     ax,MAXPORT
  34.         ja      bad_port_exit   ;err if grtr than max supported
  35.         dec     ax
  36.         js      bad_port_exit   ;no good if port nmbr was a 0
  37.         shl     ax,1
  38.         mov     bx,ax           ;get BX ready for lookup operations
  39.         mov     si,wDG __port_dta_tbl[bx] ;pnt SI to struc for this port
  40.         mov     dx,COM_BASE     ;get base address for this com port
  41.         or      dx,dx           ;set NZ if port initialized, also clrs CY
  42.         ret
  43. bad_port_exit:
  44.         xor     ax,ax           ;set ZR flag to indicate port not initialized
  45.         mov     ax,R_NOPORT
  46.         stc                     ;indicate invalid port
  47.         ret                     ;back to caller
  48. __ck_port_arg   endp
  49.  
  50. ;--------------------------------------------------------------------------
  51. ;  Translate baud-parity-databit-stopbit string to comm chip language
  52. ;
  53. ;    Entry: 1) SI = pointer to port data structure
  54. ;           2) BX = pointer to baud-parity-data-stopbit string  (BPDS_str)
  55. ;
  56. ;    Exit : 1) Return code in AX  --  ZR = success, NZ = bad data
  57. ;           2) Sets port_dta variables BAUD_DVSR & PDSINFO only, does
  58. ;              not change actual BPDS (call set_bpds to perform act chng)
  59. ;--------------------------------------------------------------------------
  60. localproc       __convert_bpds
  61. public          __convert_bpds
  62. ;---- Baud rate translation
  63.         xor     ax,ax
  64.         mov     dx,ax
  65.         mov     cx,ax           ;AX=DX=CX == 0
  66. cnvrt_baud:
  67.         mov     cl,[bx]         ;get byte from string
  68.         sub     cl,'0'          ;adjust Ascii # to binary
  69.         jb      baud_chk
  70.         cmp     cl,0ah
  71.         jae     baud_chk        ;done cnvrting baud to bin if not numeric dgt
  72.         mul     times_ten       ;mul ongoing result by 10 since reading dec #
  73.         add     ax,cx           ;add in this digit's value
  74.         inc     bx
  75.         jmp s   cnvrt_baud      ;loop till all baud characters are read
  76. baud_chk:
  77.         or      ax,ax
  78.         jz      baud_err        ;error if baud rate is 0
  79.         cmp     ax,19200        ;baud rate must be less than or equal to 19.2K
  80.         jbe     calc_dvsr       ;jmp if valid baud rate,
  81. baud_err:
  82.         mov     ax,R_BAUDERR    ;else return an error
  83.         ret
  84. calc_dvsr:
  85.         mov     cx,ax
  86.         mov     dx,1
  87.         mov     ax,0c200h       ;DX_AX = 115200 == nmbr used to calc baud divsr
  88.         div     cx
  89.         mov     BAUD_DVSR,ax    ;save baud divisor
  90. ;---- Parity bit translation
  91.         mov     dl,0            ;clear reg to hold parity,data,stop bit info
  92.         mov     al,[bx]
  93.         inc     bx              ;get parity identifier and incrmnt str ptr
  94.         and     al,0dfh         ;cnvrt to upper case
  95.         cmp     al,'N'
  96.         je      dta_bit_cnvrt   ;no action necessary if using 'NO PARITY'
  97.         cmp     al,'E'
  98.         jne     ck_if_odd
  99.         or      dl,00011000b    ;bits to set even parity
  100.         jmp s   dta_bit_cnvrt
  101. ck_if_odd:
  102.         cmp     al,'O'
  103.         je      mask_odd        ;jmp if odd parity
  104.         mov     ax,R_PARITYERR  ;no good if not even, odd, or none
  105.         ret
  106. mask_odd:
  107.         or      dl,00001000b    ;bits to set odd parity
  108. ;---- Number data bits translation
  109. dta_bit_cnvrt:
  110.         mov     al,[bx]
  111.         inc     bx              ;get data bit idntfr & incrmnt strng ptr
  112.         cmp     al,'8'
  113.         jne     ck_if_7
  114.         or      dl,00000011b    ;bits to set up for 8 data bits
  115.         mov     STRIP_MASK,0ffh ;set strip mask so no bit stripping occurs
  116.         jmp s   stp_bit_cnvrt
  117. ck_if_7:
  118.         cmp     al,'7'
  119.         je      mask_7          ;jmp if 7 data bits,
  120.         mov     ax,R_DTABITERR
  121.         ret                     ;else load err code and back to caller
  122. mask_7:
  123.         or      dl,00000010b    ;bits to up for 7 data bits
  124.         mov     STRIP_MASK,7fh  ;set strip mask to remove high bits
  125. ;---- Number of stop bits translation
  126. stp_bit_cnvrt:
  127.         mov     al,[bx]
  128.         inc     bx
  129.         cmp     bptr [bx],0
  130.         je      ckif_1stp       ;ok if string properly terminated,
  131.         mov     ax,R_BADARG
  132.         ret                     ;else show BADARG error and exit
  133. ckif_1stp:
  134.         cmp     al,'1'
  135.         je      good_bpds       ;convrt done if using 1 stop bit
  136.         cmp     al,'2'
  137.         je      msk_2stps
  138. stopbiterr:
  139.         mov     ax,R_STPBITERR
  140.         ret                     ;error if not either 1 or 2 stop bits
  141. msk_2stps:
  142.         or      dl,00000100b    ;bits to setup for 2 stop bits
  143. good_bpds:
  144.         mov     PDSINFO,dl      ;save parity, data, stopbit info
  145.         xor     ax,ax           ;set flag showing successful conversion
  146.         ret                     ;back to caller
  147. __convert_bpds  endp
  148.  
  149. ;---------------------------------------------------------------------------
  150. ; This procedure is used to perform the actual change of the line settings
  151. ; of the communications chip.
  152. ;
  153. ;  Entry: SI = pointer to com port data structure
  154. ;         COM_BASE, BAUD_DVSR, PDSINFO in struc preset to desired values
  155. ;
  156. ;  Exit : Communications chip baud rate, parity, dta bits, and stp bits set
  157. ;         Interrupts disabled
  158. ;---------------------------------------------------------------------------
  159. localproc       __set_bpds
  160. public          __set_bpds
  161.         cli
  162.         mov     dx,COM_BASE     ;(xF8) get ptr to slctd I/O port
  163.         add     dx,3            ;(xFB) select line control register (LCR)
  164.         mov     al,80h
  165.         out     dx,al           ;set high bit of LCR tells chip baud is coming
  166.         jmp s   $+2
  167.         mov     ax,BAUD_DVSR
  168.         sub     dx,3            ;(xF8) port for LSB of baud rate divisor
  169.         out     dx,al           ;send LSB of divisor
  170.         jmp s   $+2
  171.         inc     dx              ;(xF9) port for MSB of baud rate divisor
  172.         mov     al,ah
  173.         out     dx,al           ;send MSB of divisor
  174.         jmp s   $+2
  175.         mov     al,PDSINFO      ;get parity, #dtabits, #stpbits info
  176.         inc     dx
  177.         inc     dx              ;(xFB) back to LCR register
  178.         out     dx,al           ;send line infor, also clrs baud dvsr mode
  179.         ret
  180. __set_bpds      endp
  181.  
  182. endseg          COMM_TEXT
  183.         end
  184.  
  185.